package com.wangzh.concurrent.vol;

import java.util.concurrent.TimeUnit;

public class VolatileDemo1 {
    public static volatile boolean flag=true;
    public static void main(String[] args) {

        new Thread(() ->{
            while (flag){

            }
            System.out.println("====end");
        }).start();

        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("turn flag off");
        flag=false;
    }
}
